Skip to main content

On Notification State Changed Event

Triggered whenever an existing notification’s read/unread or other state attributes are updated.

  • Purpose: Let your application react to state changes—e.g. marking a notification as read, dismissed, or completed—so you can update UI badges, local storage, and any in-memory lists.

  • Functionality: The handler receives a NotificationModel payload, typically containing:

    • notification.id (string) – Unique identifier of the notification.
    • notification.isRead (boolean) – New read/unread status.
    • Other state flags.
  • Usage:

    1. Update your in-memory list (Redux, React state) to reflect the new isRead or other flags.
    2. Persist the updated notification list in local cache (AsyncStorage, SQLite).
    3. Recompute any derived UI state, such as unread counters or badge icons.
  • Example:

    import { NotificationModel } from '@one37id/mobile-js-sdk';
    import { eventEmitter } from '../services';
    import AsyncStorage from '@react-native-async-storage/async-storage';

    const handlers: EventHandlers = {
    onNotificationStateChanged: async (model: NotificationModel) => {
    console.debug(
    `Notification state changed: ${JSON.stringify(model, null, 2)}`
    );
    // broadcast internally using events or dispatch redux action
    eventEmitter.emit('changeNotificationState', { notification: model });
    },
    };

    In your UI layer (e.g. notifications screen) subscribe and update state:

    Example:

    useEffect(() => {
    const handleNotificationChanged = async ({ notification }) => {
    setState(prev => {
    const updated = prev.notifications.map(n =>
    n.id === notification.id ? notification : n
    );
    return { ...prev, notifications: updated, unreadCount: updated.filter(n => !n.isRead).length };
    });
    };
    eventEmitter.on('changeNotificationState', handleNotificationChanged);
    return () => {
    eventEmitter.off('changeNotificationState', handleNotificationChanged);
    };
    }, []);

X

Graph View